//    Copyright (C) Kherty.  All rights reserved.
using System.Windows;
using System.Windows.Media;
using OpenLS.Core.Serialization;
using OpenLS.Spreadsheet.Office2003;

namespace OpenLS.Spreadsheet.Internals
{
    partial class Font: IOffice2003XmlSerializable
    {
        #region IXmlSpreadsheetSerializable Members

        void IOffice2003XmlSerializable.ReadXmlSpreadsheet(ReadContext context)
        {
            using (ReadContext c = context.Read("Font"))
            {
#if DEBUG
                UnFreeze();
#endif
                if (c.GetOptionalBoolean(c.Namespace + "Bold", false))
                    FontWeight = FontWeights.Bold;
                if (c.GetOptionalBoolean(c.Namespace + "Italic", false))
                    FontStyle = FontStyles.Italic;
                string color = c.GetOptionalString(c.Namespace + "Color");
                if (color != null && color != "Automatic")
                    _color = ((Color)ColorConverter.ConvertFromString(color));
                string fn = c.GetOptionalString(c.Namespace + "FontName");
                if (fn != null)
                    FontFamily = new FontFamily(fn);
                double? sz = c.GetOptionalDouble(c.Namespace + "Size");
                if (sz != null)
                    _size = sz.Value;
                else
                    _size = 10;
                UnderlineType2003? underline = c.GetOptionalEnum<UnderlineType2003>(c.Namespace + "Underline");
                if (underline != null)
                    Underline = (UnderlineType)underline.Value;
                if (c.GetOptionalBoolean( c.Namespace + "Outline", false))
                    Outline = true;
                if (c.GetOptionalBoolean(c.Namespace + "Shadow", false))
                    Shadow = true;
                if (c.GetOptionalBoolean(c.Namespace + "StrikeThrough", false))
                    Strike = true;
#if DEBUG
                Freeze();
#endif
            }
        }

        #endregion
    }
}